home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 22
/
Cream of the Crop 22.iso
/
doom
/
server_1.zip
/
_VOTE.QC
< prev
next >
Wrap
Text File
|
1996-10-04
|
10KB
|
329 lines
/*
**
** _vote.qc (Vote Code, 1.1)
**
** Copyright (C) 1996 Johannes Plass
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**
** Author: Johannes Plass (plass@dipmza.physik.uni-mainz.de)
**
*/
void(entity player) VoteInfo =
{
if (!USE_MODULE_VOTE) return;
// 123456789#123456789#123456789#12345678
sprint(player,"£");
sprint(player," Vote");
sprint(player, " allows to vote. Type\n");
sprint(player," 'help-vote' for help.\n");
};
void(entity player) VoteInit =
{
if (!USE_MODULE_VOTE) return;
stuffcmd(player,"alias help-vote \"impulse 211\";\n");
stuffcmd(player,"alias votes \"impulse 212\";\n");
if (USE_SUBMODULE_VOTE_EXIT) {
stuffcmd(player,"alias vote-exit \"impulse 213\";\n");
}
if (USE_SUBMODULE_VOTE_EXITRULES) { //#jp#(ExitRules)
stuffcmd(player,"alias vote-exitrules \"impulse 214\";\n"); //#jp#(ExitRules)
} //#jp#(ExitRules)
};
void(entity player) VoteActiveMessage =
{
if (!USE_MODULE_VOTE) return;
// 123456789#123456789#123456789#12345678
sprint(player," Vote (help-vote)\n");
};
void(entity player) VoteHelp =
{
if (!USE_MODULE_VOTE) return;
// 123456789#123456789#123456789#12345678
sprint(player,"Vote:");
sprint(player, " vote via one of the commands\n");
VoteExitHelp(player);
VoteExitRulesHelp(player); //#jp#(ExitRules)
sprint(player,"The command 'votes' shows current\n");
sprint(player,"voting statistics.\n");
};
void(entity player) VoteShowVotes =
{
local float num2,req_votes;
local string numstr;
//dprint("VoteShowVotes: executing\n");
if (!USE_MODULE_VOTE) return;
VoteCheckVotes();
req_votes = 0;
if (!vote_level_has_exit && exitrules_maxfrags >= EXITRULES_FRAGLIMIT) {
req_votes = 1;
} else {
num2 = vote_voters;
while (num2 > 0) { req_votes = req_votes + 1; num2 = num2 - 2; }
}
// 123456789#123456789#123456789#12345678
sprint(player,"Statistics for ");
numstr = ftos(vote_voters);
sprint(player,numstr);
if (vote_voters != 1) sprint(player," voters:\n");
else sprint(player," voter:\n");
if (USE_SUBMODULE_VOTE_EXITRULES) { //#jp#(ExitRules)
sprint(player," vote-exitrules: "); //#jp#(ExitRules)
if (exitrules_status == EXITRULES_STATUS_TIGHT) { //#jp#(ExitRules)
numstr = ftos(vote_pro_exitrules); //#jp#(ExitRules)
sprint(player,numstr); //#jp#(ExitRules)
sprint(player," ("); //#jp#(ExitRules)
numstr = ftos(req_votes); //#jp#(ExitRules)
sprint(player,numstr); //#jp#(ExitRules)
sprint(player," required)"); //#jp#(ExitRules)
sprint(player,"\n"); //#jp#(ExitRules)
} else { //#jp#(ExitRules)
sprint(player,"exiting is allowed\n"); //#jp#(ExitRules)
} //#jp#(ExitRules)
} //#jp#(ExitRules)
if (USE_SUBMODULE_VOTE_EXIT) {
sprint(player," vote-exit: ");
if (vote_exit_status & VOTE_EXIT_ENABLED) {
numstr = ftos(vote_pro_exit);
sprint(player,numstr);
sprint(player," (");
numstr = ftos(req_votes);
sprint(player,numstr);
sprint(player," required)");
sprint(player,"\n");
} else {
sprint(player,"disabled\n");
}
}
};
float() VoteThink =
{
//dprint("VoteThink: executing\n");
if (!USE_MODULE_VOTE) {
vote_checktime = vote_checktime + 500000;
return;
}
if (!vote_checktime) {
// don't allow voting for exiting on start level
if (world.model == "maps/start.bsp") vote_exit_status = VOTE_EXIT_DISABLED;
else vote_exit_status = VOTE_EXIT_ENABLED;
vote_level_has_exit = 1;
if (world.model == "maps/end.bsp") vote_level_has_exit = 0;
else if (world.model == "maps/dm1.bsp") vote_level_has_exit = 0;
else if (world.model == "maps/dm2.bsp") vote_level_has_exit = 0;
else if (world.model == "maps/dm3.bsp") vote_level_has_exit = 0;
else if (world.model == "maps/dm4.bsp") vote_level_has_exit = 0;
else if (world.model == "maps/dm5.bsp") vote_level_has_exit = 0;
else if (world.model == "maps/dm6.bsp") vote_level_has_exit = 0;
vote_checktime = time + 40;
return;
}
if (time < 60) return; // make sure all player are in the level
vote_checktime = time + 10;
VoteCheckVotes();
if (!vote_level_has_exit) {
if (exitrules_maxfrags >= EXITRULES_FRAGLIMIT) {
if (!vote_exit_announced) {
// 123456789#123456789#123456789#12345678
bprint("Vote:");
bprint( " a single vote suffices to exit\n");
bprint("the level now.\n");
vote_exit_announced = 1;
}
if (vote_voters && vote_pro_exit) {
VoteExitExit();
return;
}
if (vote_voters && vote_pro_exitrules) {
VoteExitRulesDisable();
return;
}
}
}
if (vote_voters && vote_pro_exit) {
if (vote_pro_exit >= vote_voters * 0.5) {
VoteExitExit();
return;
}
}
if ( vote_voters && vote_pro_exitrules //#jp#(ExitRules)
&& (vote_pro_exitrules >= vote_voters * 0.5)) { //#jp#(ExitRules)
VoteExitRulesDisable(); //#jp#(ExitRules)
} //#jp#(ExitRules)
};
void() VoteCheckVotes =
{
local entity e;
//dprint("VoteCheckVotes: executing\n");
vote_voters = vote_pro_exitrules = vote_pro_exit = 0;
e = find(world, classname, "player");
while (e != world) {
if (!PlayerStatusPlayerIsBogusPlayer(e)) {
vote_pro_exitrules = vote_pro_exitrules + e.vote_exitrules;
vote_pro_exit = vote_pro_exit + e.vote_exit;
vote_voters = vote_voters + 1;
}
e = find(e, classname, "player");
}
};
/*
===============================================================
Voting for exiting immediately
===============================================================
*/
void(entity player) VoteExitHelp =
{
local string f;
if (!USE_MODULE_VOTE) return;
if (!USE_SUBMODULE_VOTE_EXIT) return;
// 123456789#123456789#123456789#12345678
sprint(player," vote-exit: the majority may decide\n");
sprint(player," to exit the level immediately.\n" );
sprint(player," Onls without exit a single\n");
sprint(player," vote suffices to exit\n" );
sprint(player," once " );
f = ftos(EXITRULES_FRAGLIMIT);
sprint(player, f );
sprint(player, " frags are reached.\n" );
};
void(entity player) VoteExitVote =
{
if (!USE_MODULE_VOTE) return;
if (!USE_SUBMODULE_VOTE_EXIT) return;
if (vote_exit_status & VOTE_EXIT_DISABLED) {
// 123456789#123456789#123456789#12345678
sprint(player,"Voting for exiting is not possible\non this level.\n");
return;
}
if (player.vote_exit) {
player.vote_exit = 0;
sprint(player,"Vote against exiting accepted\n");
} else {
player.vote_exit = 1;
sprint(player,"Vote for exiting accepted\n");
}
vote_checktime = -100;
};
void() VoteExitExit =
{
local float f;
if (!USE_MODULE_VOTE) return;
if (!USE_SUBMODULE_VOTE_EXIT) return;
f = 0;
if (!vote_level_has_exit) {
if (exitrules_maxfrags >= EXITRULES_FRAGLIMIT) {
if (vote_pro_exit) {
f = 1;
bprint ("A player decided to exit.\n");
if (USE_MODULE_SERVERCONSOLE) { //#jp#(ServerConsole)
dprint ("A player decided to exit.\n"); //#jp#(ServerConsole)
} //#jp#(ServerConsole)
}
}
}
if (!f) {
bprint ("The majority decided to exit.\n");
if (USE_MODULE_SERVERCONSOLE) { //#jp#(ServerConsole)
dprint ("The majority decided to exit.\n"); //#jp#(ServerConsole)
} //#jp#(ServerConsole)
}
NextLevel();
};
/*
===============================================================
Voting for disabling ExitRules
//#jp#(ExitRules)
===============================================================
*/
void(entity player) VoteExitRulesHelp =
{
if (!USE_MODULE_VOTE) return;
if (!USE_MODULE_EXITRULES) return;
if (!USE_SUBMODULE_VOTE_EXITRULES) return;
// 123456789#123456789#123456789#12345678
sprint(player," vote-exitrules: the majority may \n");
sprint(player," disable the current ExitRules.\n");
};
void(entity player) VoteExitRulesVote =
{
if (!USE_MODULE_VOTE) return;
if (!USE_MODULE_EXITRULES) return;
if (!USE_SUBMODULE_VOTE_EXITRULES) return;
if (exitrules_status != EXITRULES_STATUS_TIGHT) {
// 123456789#123456789#123456789#12345678
sprint(player,"ExitRules are disbled on this level,\nvoting is not necessary.\n");
return;
}
// 123456789#123456789#123456789#12345678
sprint(player,"Vote for disabling ExitRules accepted\n");
player.vote_exitrules = 1;
vote_checktime = -100;
};
void() VoteExitRulesDisable =
{
//dprint("VoteExitRulesDisable: executing\n");
if (!USE_MODULE_VOTE) return;
if (!USE_MODULE_EXITRULES) return;
if (!USE_SUBMODULE_VOTE_EXITRULES) return;
if (exitrules_status != EXITRULES_STATUS_TIGHT) return;
// 123456789#123456789#123456789#12345678
bprint ("The majority disbled ExitRules, you\nmay exit at any time.\n");
if (USE_MODULE_SERVERCONSOLE) { //#jp#(ServerConsole)
dprint ("The majority disabled ExitRules.\n"); //#jp#(ServerConsole)
} //#jp#(ServerConsole)
exitrules_status = EXITRULES_STATUS_SOFT;
};